<%--
  Created by IntelliJ IDEA.
  User: ZXW
  Date: 2019/8/19
  Time: 0:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>
    <title>用户更新</title>
    <script type="text/javascript" src="${requestPath}/resources/js/jquery-3.4.1.js"></script>
</head>
<body bgcolor="#7fff00">

<h1 align="center"><b>更新用户信息</b></h1>
<div>
    <form action="/update" method="post">
        <div align="center">
            <label for="id">编号</label>
            <input id="id" name="Id" type="Id" value="${user.id}" disabled>
        </div>
        <div align="center">
            <label for="userName">用户名</label>
            <input id="userName" name="userName" type="text" value="${user.userName}">
        </div>
        <div align="center"> <label for="passWord">密码</label>
            <input id="password" name="password" type="password" value="${user.passWord}">
        </div>
        <div align="center"><label for="email">邮箱地址</label>
            <input id="email" name="email" type="email" value="${user.email}">
        </div>
        <div align="center"><label for="phoneNumber">联系电话</label>
            <input id="phoneNumber" name="phoneNumber" type="phoneNumber" value="${user.phoneNumber}">
        </div>
        <div align="center"><a href="#" onclick="updateUser('${user.id}')">更新</a> </div>
    </form>
</div>
<script>
    function updateUser(id){

        var flag =confirm("是否更新"+id+"？");
        if(!flag){
            return;
        }
        var userName = $("#userName").val();
        var password = $("#password").val();
        var email = $("#email").val();
        var phoneNumber = $("#phoneNumber").val();
        $.ajax(
            {
                url:"${requestPath}/update?Id="+id+"&userName="+userName+"&password="+password+"&email="+email+"&phoneNumber="+phoneNumber,
                async:false,
                type:'get',

                success:function (data){
                    if(data.flag){
                        alert("更新成功！");
                        location.href="${requestPath}/query";       <!--返回到query方法-->
                    }else{
                        alert(data.msg);
                    }
                }
            }
        );


    }
</script>
</body>
</html>
